﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine;
using Microsoft.Xna.Framework;

namespace Engine
{
    public class ScreenManager : GameComponent
    {
        Dictionary<string, UIScreen> Screens;

        UIScreen activeScreen = null;
        public ScreenManager(Game _game)
            : base(_game)
        {
            Screens = new Dictionary<string, UIScreen>();
        }

        public void AddScreen(string _name, UIScreen _screen)
        {
            if (ShowScreen(_name))
                return;
            activeScreen = _screen;
            Screens[_name] = _screen;
            activeScreen.SetScreenManager(this);
            activeScreen.Show();
        }

        public bool ShowScreen(string _name)
        {
            if (Screens.ContainsKey(_name))
            {
                activeScreen = Screens[_name];
                activeScreen.Show();
                return true;
            }
            return false;
        }

        public override void Update(GameTime _gameTime)
        {
            if (activeScreen != null)
            {
                activeScreen.Update(_gameTime);
                activeScreen.Draw();
            }
        }
    }
}
